package org.makcro.sms.services.chat.web.client.widgets.subscirbers;

import org.makcro.sms.services.chat.web.shared.dto.SubscriberDto;

import com.extjs.gxt.ui.client.core.Template;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.Params;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;

public class UnsubscribedGridCellRendererImpl implements GridCellRenderer<SubscriberDto> {

	private Template	template				= new Template( "<span style='color:{textColor}'>{value}</span>" );
	private String		unsubscribedTextColor	= "#0066FF";
	private String		subscribedTextColor		= "#CC0000";
	private String		unsubscribedValue		= "Da";
	private String		subscribedValue			= "Ne";

	@Override
	public Object render(SubscriberDto model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<SubscriberDto> store, Grid<SubscriberDto> grid) {
		Boolean isUnsubscribed = model.isUnsubscribed();
		// set template param values
		Params params = new Params();
		params.set( "textColor", isUnsubscribed ? subscribedTextColor : unsubscribedTextColor );
		params.set( "value", isUnsubscribed ? unsubscribedValue : subscribedValue );
		String appliedTemplate = template.applyTemplate( params );

		return appliedTemplate.toString();
	}
}
